<template>
  <div class="app-container">
    <div class="table-page-search-wrapper">
      <el-form :inline="true" label-width="100px">
        <el-row :gutter="18">
          <el-col :md="6" :sm="24">
            <el-form-item label="加工单号">
              <el-input
                v-model="queryParam.processNum"
                placeholder="请输入加工单号"
                clearable
                @keyup.enter.native="onSearch"
                @clear="onSearch"
              />
            </el-form-item>
          </el-col>
          <el-col :md="4" :sm="24">
            <span
              class="table-page-search-submitButtons"
              :style="
                (advanced && { float: 'right', overflow: 'hidden' }) || {}
              "
            >
              <el-button
                v-waves
                type="primary"
                icon="el-icon-search"
                @click="onSearch"
              >
                查询
              </el-button>
              <el-button type="info" icon="el-icon-refresh" @click="reset">
                重置
              </el-button>
              <el-link
                type="primary"
                :underline="false"
                @click="toggleAdvanced"
              />
            </span>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <el-table
      v-loading="loadingData"
      :data="list"
      element-loading-text="Loading"
      fit
      highlight-current-row
      row-key="id"
      @sort-change="appendSorterParam"
      @current-change="currentSelect"
    >
      <el-table-column align="center" label="加工单号">
        <template slot-scope="scope">
          <span>
            {{ scope.row.processNum }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="生产计划">
        <template slot-scope="scope">
          <span>
            {{ scope.row.bomBomName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="加工单数量">
        <template slot-scope="scope">
          <span>
            {{ scope.row.processQuantity }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="班次">
        <template slot-scope="scope">
          <span>
            {{ scope.row.workTeamTeamName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="备料">
        <template slot-scope="scope">
          <span>
            {{ scope.row.pickStatusLabel }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="状态">
        <template slot-scope="scope">
          <span>
            {{ scope.row.statusLabel }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="开始时间">
        <template slot-scope="scope">
          <span>{{ scope.row.processStartTime }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="结束时间">
        <template slot-scope="scope">
          <span>{{ scope.row.processEndTime }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="备注">
        <template slot-scope="scope">
          <span>
            {{ scope.row.remark }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="230"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{ row }">
          <el-button
            v-permission="['detail']"
            type="text"
            @click="
              $router.push({ name: 'worksheetEdit', query: { id: row.id } })
            "
          >
            编辑
          </el-button>
          <span
            v-permission="['detail']"
            v-permission-again="['update', 'delete']"
          >
            <el-divider direction="vertical" />
          </span>
          <el-button
            v-permission="['detail']"
            type="text"
            @click="showResume(row)"
          >
            工件履历
          </el-button>
          <span
            v-permission="['detail']"
            v-permission-again="['update', 'delete']"
          >
            <el-divider direction="vertical" />
          </span>
          <el-button v-permission="['detail']" type="text" @click="showQr(row)">
            <i class="el-icon-camera" />
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="pagination.total > 0"
      :total="pagination.total"
      :page.sync="pagination.current"
      :limit.sync="pagination.pageSize"
      :style="{ textAlign: 'right' }"
      @pagination="handlePaginationChanged"
    />
  </div>
</template>

<script>
import list from '@/components/diboot/mixins/list'
import waves from '@/directive/waves'

export default {
  name: 'WorksheetList',
  directives: { waves },
  mixins: [list],
  data() {
    return {
      baseApi: '/worksheet',
      getListFromMixin: true,
      attachMoreList: [
        {
          target: 'PROCESSING'
        }
      ],
      drawer: false,
      currentSelectData: {},
      feedingData: [],
      selectRowInfo: {}
    }
  },
  methods: {
    currentSelect(val) {
      this.selectRowInfo = val
    },
    showResume(row) {
      this.currentSelectData = row
      this.drawer = true
    },
    showQr(row) {
      const qrString = JSON.stringify({
        id: row.id,
        processNum: row.processNum,
        goodsId: row.goodsId,
        QRCode: 'ProcessingOrder'
      })
      this.$refs.qrCode.open(row.processNum, qrString)
    }
  }
}
</script>
<style lang="scss" scoped></style>
